import {request} from "@umijs/max";
import * as API from "@/services";

export const UPLOAD_FILE_API_PATH = `/api/v1/upload-file`;
export const UPLOAD_BASE64_IMG_API_PATH = `/api/v1/upload-base64img`;

export async function queryUploadFile(filename: string, originalFilename: string, uploadServiceType?: string): Promise<API.RespResult<string>> {
    return request(`/api/v1/search-upload-file`, {
        method: 'GET',
        params: {
            filename,
            originalFilename,
            uploadServiceType
        },
    });
}


export async function uploadBase64File(base64: string): Promise<API.RespResult<any>> {
    return request(UPLOAD_BASE64_IMG_API_PATH, {
        method: 'POST',
        data: {
            data: [base64]
        },
    });
}


export async function queryAliyunOssUploadPolicy(bucketName: string, dir: string): Promise<API.RespResult<API.AliyunOssPolicyResult>> {
    return request(`/api/v1/upload/aliyun/oss/policy`, {
        method: 'POST',
        params: {
            bucketName,
            dir
        },
    });
}


export async function queryAliyunOssUploadPresigned(filename: string, originalFilename: string): Promise<API.RespResult<API.AliyunOssPresignInfo>> {
    return request(`/api/v1/upload/aliyun/oss/presigned`, {
        method: 'POST',
        params: {
            filename,
            originalFilename,
        },
    });
}

export async function queryCtyunOssUploadPresigned(filename: string, originalFilename: string): Promise<API.RespResult<API.CtyunOssPresignInfo>> {
    return request(`/api/v1/upload/ctyun/oss/presigned`, {
        method: 'POST',
        params: {
            filename,
            originalFilename,
        },
    });
}
